﻿using System;
using System.Collections;
using System.Configuration;
using System.Data; 
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Microsoft.JCI.Common.Utility;
using Microsoft.JCI.Bll;
using Microsoft.JCI.Common.Entity;
using System.Collections.Generic; 

namespace Microsoft.JCI.Portal.UserControl
{
    public partial class DispatchByBranch : System.Web.UI.UserControl
    {
        public string CompanyCode
        {
            get
            {
                return ddlSendTo.SelectedValue;
            }
        }

        public string CurrentBrunch
        {
            get
            {
                if (this.ViewState["CurrentBranch"] == null)
                {
                    this.ViewState["CurrentBranch"] = string.Empty;
                }
                return this.ViewState["CurrentBranch"].ToString();
            }
            set { this.ViewState["CurrentBranch"] = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {  
                LoadCompany();
            }


        }

        private void LoadCompany()
        { 
            MasterDataBll bll = new MasterDataBll();
            List<SysCompanyEntity> list = bll.GetCompanyListFromCache(Enumerator.CompanyType.Vendor);
            if (CurrentBrunch != string.Empty)
            {
                list = list.FindAll(p => p.ParentCompanyCode == this.CurrentBrunch);
            }
            ddlSendTo.DataSource = list;
            ddlSendTo.DataTextField = "Name";
            ddlSendTo.DataValueField = "CompanyCode";
            ddlSendTo.DataBind();
        }

        protected void rblSendTo_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadCompany();
        }
    }
}